package com.complex.spring.mvc.servlet;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyFilter1 implements Filter{

	private String str;
	
	public void destroy() {
	
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		
		//设置filter_str
		request.setAttribute("filter_str", str+":MyFilter1_Before==>");
		chain.doFilter(request, response);
		
		//重新设置filter_str
		str = (String)request.getAttribute("filter_str");
		request.setAttribute("filter_str", str+"MyFilter1_After==>");
		
		request.getRequestDispatcher("jsp/myservlet.jsp").forward(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		//取web.xml中配置的参数  xml中获取的参数类型为String
		str = filterConfig.getInitParameter("filter_str");
		
	}

}
